package Card;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Card {
    public int rank;
    public char suit;
    public Card(int rank, char suit){
        this.rank = rank;
        this.suit = suit;
    }
    @Override
    public String toString(){
        return rank + " " + suit;
    }
}
class BuyCards{
    public static final char[] SUIT = {'♣','♥','♣','♦'};
    public List<Card> buyPlayCards(){
        List<Card> cards = new ArrayList<>();
        for(int i = 1; i <= 13; i++){
             for(int j = 0; j < 4; j++){
                 Card card = new Card(i,SUIT[j]);
                 cards.add(card);
             }
        }
        return cards;
    }
    public void shuffle(List<Card> cards){
        for(int i = cards.size() - 1; i > 0; i--){
            Random random = new Random();
            int index = random.nextInt(i);//产生0~i的随机数
            swap(cards, i, index);
        }
    }
    private void swap(List<Card> cards, int i, int j){
        Card tmp = cards.get(i);
        cards.set(i, cards.get(j));
        cards.set(j,tmp);
    }
    public List<List<Card>> pickCard(List<Card> cards){
        List<Card> player1 = new ArrayList<>();
        List<Card> player2 = new ArrayList<>();
        List<Card> player3 = new ArrayList<>();
        //将这三人联系起来
        List<List<Card>> player = new ArrayList<>();
        player.add(player1);
        player.add(player2);
        player.add(player3);
        //共5轮，三人每人轮流拿一张牌
        for(int i = 0; i < 5; i++){
            for(int j = 0; j < 3; j++){
                player.get(j).add(cards.get(i));
                cards.remove(0);
            }
        }
        return player;
    }
}
